Skip to main content
Version: Next

(Android) detekt guideline

detekt has been selected as the static code analysis tool to be used for Android PR build pipeline. It is incorporated as a mandatory step in the PR build process, to help us keep the code up to the industry standards.

project configuration

detekt was configured as a Gradle Plugin and applied to the common-android-lib precompiled Plugin, which is the shared base for all Navida-Plugin modules. With this configuration, detekt Gradle tasks are available for all Navida-Plugin modules, without any installation or configuration effort for all developers. As an example, any developer can execute

./gradlew aokselection:detekt

from the local machine. The results should be equivalent to those from the Azure DevOps build pipeline.

detekt rules are configured via detekt/detekt-config.yml file. Rules from this file are applied on top of default rules set. The content of detekt/detekt-config.yml is subject to change, if commonly agreed that certain rule is invalid for any reason. Use the Guild chat to start a discussion, if needed.

There are also 2 scripts created to ease the work with detekt:

  • script/detekt-run.sh which executes Gradle detekt task for each module - directly used by Azure DevOps
  • script/detekt-recreate-baseline.sh which recreates detekt-baseline.xml for each module. See below for details

detekt-baseline.xml configuration

Thanks to the so called baseline configuration files, detekt is able to suppress existing issues for legacy projects while making sure no new issues are introduced. There is a detekt-baseline.xml file created for each Navida-Plugin module and committed to the Git repository. Any change to the detekt-baseline.xml file (other than removal of a suppress) should be taken with extra caution and explained in-depth while a PR is in code-review.

IMPORTANT: detekt-baseline.xml files contain lists of issues addressed by the signature, like for example:

<ID>TopLevelPropertyNaming:ChallengeNavigation.kt$const val challengeID = "challenge_id"</ID>

<ID>MagicNumber:GoalDetailViewModel.kt$GoalDetailViewModel$72</ID>

<ID>LargeClass:GoalDetailViewModel.kt$GoalDetailViewModel : BaseViewModel</ID>

note that any change to the signature (eg. adding extra parameter to a method or moving a constant to another file) invalidates the suppress and will cause the issue to be reported by the CI.

how to proceed

If there are issues reported by the CI, please use following algorithm to determine next steps

  1. If an issue is reported directly to the code developed with a PR: it must be fixed before merge can happen. We cannot decrease the quality of the code.
  2. If an issue is reported because the signature of a suppress got invalidated:
    1. Try to fix the issue. Most of the issues are easy and quick to fix. There is no other way to improve the quality of the code as to fix issues one-by-one.
    2. If it's not feasible to fix the issue: regenerate the baseline for a given module. Pay extra attention not to include suppress for the issues from point 1. Add extra comments in the PR.
  3. Try to execute ./gradlew module:detekt locally as much as possible - before a PR is created, and while trying to fix the issues reported. We have limited throughput of the build machines - they should not be used for debugging of static code analysis issues.
  4. If you find a rule invalid for any reason - let's start a discussion in the Android Guild Teams chat. It's very likely for a rule to get updated.
  5. Have fun :)